  <?php defined('SYSPATH') or die('No direct script access.');
  
  class Controller_Cms_Setbackend extends Controller_Template 
  {
      public $template = 'cms/template_backend';
      public $user;
      public $auth_required = true;
      public $auth_role 	= array('login');
      public $secure_actions     = array();
	 
      public function before()
      {
        parent::before();
		 
		#Open session
        $this->session= Session::instance('cookie');
 
        #Check user auth and role
         $action_name = Request::instance()->action;
		if (($this->auth_required == TRUE || in_array( $action_name, $this->secure_actions) )
				AND Auth::instance()->logged_in($this->auth_role) == FALSE)
		{
			if (Auth::instance()->logged_in()){
			    Request::instance()->redirect('account/noaccess');
			}else{
			    Request::instance()->redirect('login');
			}
		} 
 
  	    if ($this->auto_render)
  	    {
  	    	$profil = ORM::factory('user',Auth::instance()->get_user()->id)->profiles;
			$this->template->profil = $profil;
			$this->template->breadcrumb   = '';
  	    	$this->template->title   = '';
  	    	$this->template->content = '';
			//$this->template->username = '';
			//$this->template->footer = View::factory('cms/footer_backend');
			//$this->template->right = '';  
 
        }
      }

	public function after()
	{
		if ($this->auto_render)
		{			
			/* $this->template->styles = array_merge( $this->template->styles, $styles );
			$this->template->scripts = array_merge( $this->template->scripts, $scripts ); */
			#setting username for template
			if(Auth::instance()->logged_in()!= 0)
			{
				$username = Auth::instance()->get_user()->username;
				$this->template->username = $username;
			}
		}
		
		parent::after();
    }
  }